LOCALPATH=${shell pwd}
SRC_DIRS := $(shell find $(LOCALPATH) -maxdepth 4 -type d )
C_SRC_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
CPP_SRC_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
ALL_SRC_FILES = $(CPP_SRC_FILES) $(C_SRC_FILES)
OBJS = $(foreach n,$(ALL_SRC_FILES),$(addsuffix .o,$(basename ${n})))

CFLAGS = -I${LOCALPATH}/include -I${LOCALPATH}/include/os/ -I${LOCALPATH}/include/errcode -g -O2 -DUMAPIMALLOC -m64 -std=c99
all:$(OBJS)
	@echo "build libumapi.so"
	@gcc $(OBJS) -fPIC -shared -o libumapi.so ${CFLAGS}
	@ar rcs libumapi.a $(OBJS)
clean:
	@rm -f $(OBJS)
	@rm -f libumapi.so
install:all
	@echo "install libumapi.so"
	@mkdir ${INSTALLPATH}/include/umapi/ -p
	@cp -rfP libumapi.so ${INSTALLPATH}/lib/
	@cp -rfP libumapi.a  ${INSTALLPATH}/lib/
	@cp -rfP include ${INSTALLPATH}/include/umapi/
test:
	@echo "build Demo"
	@gcc test.c -L. -lumapi -o TestDemo $(CFLAGS) -lpthread	-ldl
%.o : %.c 
	@echo "build " $@
	@$(CROSS)gcc -fPIC -c -D_GNU_SOURCE $(CFLAGS) $< -o $@  -lm >/dev/null $(PQ)
